<?php
class AclSecurityController extends AppController {
    var $uses = array();
    //var $components = array('Acl');
	function beforeFilter(){}
    /**
     * 
     * Checking permissions of logined user.
     */
	function checkPermission() {
		$user = $this->Auth->user();
		$this->loadModel('User');
		$this->User->recursive = 1;
		if ($user['User']['active'] == 1) {
			if ($user['User']['type_user_id'] == 1) {
				$loginedUser = $this->User->read('User.id,User.userName,User.active,TypeUser.*,Contact.*', $user['User']['id']);
//				debug($loginUser);
				$this->Session->write('loginedUser',$loginedUser);
				$this->redirect(array('controller'=>'schools','action'=>'index'),null, true);
			} else if ($user['User']['type_user_id'] == 2) {
				$loginedUser = $this->User->read('User.id,User.userName,User.active,TypeUser.*,Contact.*,School.*', $user['User']['id']);
//				debug($loginUser);
				$this->Session->write('loginedUser',$loginedUser);
				$this->redirect(array('controller'=>'messages','action'=>'index'),null, true);
			} else {
				$loginedUser = $this->User->read('User.id,User.userName,User.active,TypeUser.*,Subscriber.*', $user['User']['id']);
				$this->Session->write('loginedUser',$loginedUser);
				$this->redirect(array('controller'=>'registers','action'=>'signup'),null, true);
			}
		} else {
			$this->Session->setFlash('This user is not active. Please contact with administrator!');
			$this->redirect($this->Auth->logout());
		}
	}
}
?>